/**
 * 右键菜单功能
 */
import {
	MessageBox,
	Message,
	Loading
} from 'element-ui'
import {
	editorMap
} from './rightEditorMap.js'
import {
	newBigeMap
} from "./map.js"
class contextMenu {
	constructor() {

	}
	// 删除
	deleteDocment() {
		// 重新渲染左部图层数据
		editorMap.updateLeftMenuData(editorMap.editObjPId, '', editorMap.editObj.id)
		// 删除自定义数据
		newBigeMap.customData.delete(editorMap.editObj.id)
		// 删除地图元素
		editorMap.editObj.remove()

		editorMap.setEdiorObjIsNull()

		editorMap.VM.editorBox = false
		// 设置地图状态为经过编辑的状态
		newBigeMap.isMapEditor = true
		// 隐藏右键菜单
		editorMap.detectionRightClickDom()
	}
	// 修改路径
	modifyPath() {
		if (editorMap.editObj) {
			editorMap.editObj.editing.enable()
			editorMap.isModifyPath = true
			editorMap.VM.editorBox = false
		}
		// 隐藏右键菜单
		editorMap.detectionRightClickDom()
	}
	// 属性
	editorDocment() {
		if (editorMap.editObj) {
			// this.editObj.editing.enable()
			editorMap.editObj.editing.disable()
		}
		const edit = newBigeMap.customData.get(editorMap.editObj.id)
		// 记录当前点击对象的Pid
		editorMap.editObjPId = edit.pId
		// console.log(edit.pId)
		// 向页面传递对象数据
		editorMap.VM.getEditorData(edit)
		// 隐藏右键菜单
		editorMap.detectionRightClickDom()
	}
	// 复制坐标
	copyLatLng() {
		const edit = newBigeMap.customData.get(editorMap.editObj.id)
		let text = `${edit.centralPoint.lng},${edit.centralPoint.lat}`

		const mapPage = document.getElementById("mapPage")
		const input = document.createElement('input')
		input.id = 'rightClickBoxInput'
		input.value = text
		mapPage.appendChild(input)
		input.select(); //选中文本

		if (document.execCommand('copy')) {
			document.execCommand('copy');
			input.parentNode.removeChild(input)
			Message.success('复制成功')
			// 隐藏右键菜单
			editorMap.detectionRightClickDom()
		}
	}
	// 全屏显示
	fullScreen() {
		let element = document.documentElement;
		let el = element;
		let rfs =
			el.requestFullScreen ||
			el.webkitRequestFullScreen ||
			el.mozRequestFullScreen ||
			el.msRequestFullScreen;
		// Element.requestFullscreen() 此方法用于发出异步请求使元素进入全屏模式。
		// 调用此API并不能保证元素一定能够进入全屏模式。如果元素被允许进入全屏幕模式，
		// document对象会收到一个fullscreenchange事件，通知调用者当前元素已经进入全屏模式。如果全屏请求不被许可，则会收到一个fullscreenerror事件。
		if (typeof rfs != "undefined" && rfs) {
			rfs.call(el);
		} else if (typeof window.ActiveXObject != "undefined") {
			let wscript = new ActiveXObject("WScript.Shell");
			if (wscript != null) {
				wscript.SendKeys("{F11}");
			}
		}
		// 隐藏右键菜单
		editorMap.detectionRightClickDom()
	}
}
export const cmf = new contextMenu()
